package panda.android.notebook.dialog;

import panda.android.notebook.R;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class KBDDialog extends BaseDialog {

	public interface Insert {
		public void inertString(String string);
	}

	Insert insert;

	public void setInsert(Insert insert) {
		this.insert = insert;
	}

	private boolean isShow = false;
	private EditText editText;

	public boolean isShow() {
		return isShow;
	}

	public KBDDialog(Context context, int theme) {
		super(context, theme);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		title.setText("键盘输入");

		layout.setOrientation(LinearLayout.VERTICAL);

		editText = new EditText(getContext());
		editText.setGravity(Gravity.TOP);
		layout.addView(editText, new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.MATCH_PARENT, 0, 1));

		Button button = new Button(getContext());
		button.setText("插入");
		button.setTextColor(Color.BLACK);
		button.setTextSize(utils.fontsize(10));
		button.setBackgroundResource(R.drawable.button);
		button.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				insert.inertString(editText.getText().toString());
				editText.setText("");
				dismiss();
			}
		});
		layout.addView(button, new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.MATCH_PARENT,
				LinearLayout.LayoutParams.WRAP_CONTENT));

		WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
		layoutParams.width = utils.width(400);
		layoutParams.height = utils.height(200);
		getWindow().setAttributes(layoutParams);
		
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		super.show();
		isShow = true;
	}

	@Override
	public void dismiss() {
		// TODO Auto-generated method stub
		super.dismiss();
		isShow = false;
	}
}
